import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_t/page/car/view/car_detail_page.dart';
import 'package:riverpod_t/routers/navigator_utils.dart';
import 'package:riverpod_t/routers/routers.dart';

class CarNavigator {
  CarNavigator._();

  static Future toCarDetailPage(BuildContext context, {required int entityId}) {
    return NavigatorUtils.push(
      context,
      _CarRoutes.carDetailPage,
      replace: false,
      clearStack: false,
      arguments: {'entityId': entityId},
    );
  }

  static ModuleRouter getRouter() {
    return _CarRoutes();
  }
}

class _CarRoutes extends ModuleRouter {
  static const carDetailPage = 'page/car/view/car_detail_page';

  @override
  void init(FluroRouter router) {
    router.define(
      carDetailPage,
      handler: Handler(
        handlerFunc: (context, params) {
          Map? argument = context!.settings!.arguments as Map?;
          int entityId = argument?['entityId'] ?? -1;
          return CarDetailPage(entityId: entityId);
        },
      ),
    );
  }
}
